# Maintainer: Kyle Keen <keenerd@gmail.com>
# Maintainer: Bruno Pagani <archange@archlinux.org>

_pkgname=qtconsole
pkgname=python-qtconsole
pkgver=5.5.1
pkgrel=1
pkgdesc="Qt-based console for Jupyter with support for rich media output"
arch=(any)
url="https://qtconsole.readthedocs.io/"
license=(BSD)
depends=(
    python-ipykernel
    python-ipython-genutils
    python-jupyter-core
    python-jupyter-client
    python-traitlets
    python-pygments
    python-pyqt6
    python-pyzmq
    python-qtpy
    qt6-svg
)
makedepends=(python-setuptools)
checkdepends=(python-pytest python-pytest-qt python-flaky xorg-server-xvfb)
source=(https://github.com/jupyter/${_pkgname}/archive/${pkgver}/${pkgname}-${pkgver}.tar.gz)
sha256sums=('5e0bc296795af042a720ec59da6bde244ef359b3e3f9aaff218d50ec96b2fd14')

build() {
  cd ${_pkgname}-${pkgver}
  python setup.py build
}

check() {
  cd ${_pkgname}-${pkgver}
  xvfb-run -s '-nolisten local' pytest -x -vv --color=yes qtconsole
}

package() {
  cd ${_pkgname}-${pkgver}
  python setup.py install --prefix=/usr --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE -t "${pkgdir}"/usr/share/licenses/${pkgname}/

  cd examples
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  sed -i "s|^Icon=.*$|Icon=${site_packages}/qtconsole/resources/icon/JupyterConsole.svg|" jupyter-qtconsole.desktop
  install -Dm644 jupyter-qtconsole.desktop -t "${pkgdir}"/usr/share/applications/
}
